<?php

class Article extends CActiveRecord {

    public function getUpdatedFormatted() {
        return ($this->updated) ? date('Y-m-d', $this->updated) : '';
    }

    /**
     * The followings are the available columns in table 'www_articles':
     * @var integer $id
     * @var string $img_saved_path
     * @var string $body
     * @var integer $created
     * @var integer $updated
     */

    /**
     * Returns the static model of the specified AR class.
     * @return CActiveRecord the static model class
     */
    public static function model($className = __CLASS__) {
        return parent::model($className);
    }

    /**
     * @return string the associated database table name
     */
    public function tableName() {
        return '{{articles}}';
    }

    /**
     * @return array validation rules for model attributes.
     */
    public function rules() {
    // NOTE: you should only define rules for those attributes that
    // will receive user inputs.
        return array(
            array('node_id, body, created, updated', 'required'),
            array('node_id, created, updated', 'numerical', 'integerOnly' => true),
            array('img_saved_path', 'length', 'max' => 200),
        );
    }

    public function behaviors() {
        return array(
            'CTimestampBehavior' => array(
                'class' => 'zii.behaviors.CTimestampBehavior',
                'createAttribute' => 'created',
                'updateAttribute' => 'updated',
            )
        );
    }

    /**
     * @return array relational rules.
     */
    public function relations() {
    // NOTE: you may need to adjust the relation name and the related
    // class name for the relations automatically generated below.
        return array(
            'node' => array(self::BELONGS_TO, 'Node', 'node_id'),
        );
    }

    /**
     * @return array customized attribute labels (name=>label)
     */
    public function attributeLabels() {
        return array(
            'id' => 'Id',
            'img_saved_path' => Yii::trace('article', 'img_saved_path'),
            'body' => Yii::t('article', 'body'),
            'created' => Yii::t('index', 'created'),
            'updated' => Yii::t('common', 'updated'),
        );
    }
}